<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>教学辅助管理系统_注册</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="lib/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/lib/sweetalert/sweetalert.css">
<link rel="stylesheet" href="css/login.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="top-content">
    <div class="container">
        <div class="row">
            <div class="text-center">
                <h2>教务辅助管理系统</h2>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6 col-sm-offset-3 form-box">
            	<div class="form-top">
            		<div class="col-sm-4 form-title">
            			<i class="fa fa-user"></i> 注册
            		</div>
            		<div class="col-sm-4 col-sm-offset-4">
            			<span class="pull-right">已有账号 <a href="login.jsp" class="text-primary">登陆</a></span>
            		</div>
                </div>
                <div class="form-bottom">
              		<form name="registerform" role="form" action="register" method="post" class="login-form" onsubmit="return check(this);">
              			<div class="form-group">
              				<label for="form-username">学号/工号</label>
                  			<input type="text" name="username" placeholder="" class="form-username form-control" id="form-username">
                  		</div>
                  		<div class="form-group">
                  			<label for="form-password1">密码</label>
                  			<input type="password" name="password1" placeholder="" class="form-password form-control" id="form-password1">
                  		</div>
                  		<div class="form-group">
                  			<label for="form-password2">确定密码</label>
                  			<input type="password" name="password2" placeholder="" class="form-password form-control" id="form-password2">
                  		</div>
                  		<div style="margin-bottom:15px">
	                  		<label class="radio-inline c-radio">
                                 <input id="inlineradio1" type="radio" name="type" value="s" checked>
                                 <span class="fa fa-circle"></span>学生</label>
	                        <label class="radio-inline c-radio">
	                           <input id="inlineradio2" type="radio" name="type" value="t">
	                           <span class="fa fa-circle"></span>教师</label>
	                    </div>
                  		<button type="submit" class="btn btn-block">注册</button>
              		</form>
             	</div>
            </div>
        </div>
    </div>   
</div>
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="<%=request.getContextPath()%>/lib/sweetalert/sweetalert.min.js"></script>
<script>
	//表单提交前进行数据验证，数据合法则返回true表单提交
	function check(registerform) {  
		if(registerform.username.value=="") {
			swal("学号/工号不能为空", "请重新输入", "warning")
    		return false;
    	}
    	else if(!isNumber(registerform.username.value)) {
    		swal("学号/工号不合法","请重新输入","warning");  
	        return false;  
    	}
    	else if(registerform.password1.value=="" || registerform.password1.value.length<6) {
    		swal("密码长度不小于6","请重新输入","warning");  
	        return false; 
    	}
    	else if(registerform.password1.value!=registerform.password2.value) {  
 	   	    swal("两次密码输入不相同","请重新输入","warning");   
 	        return false;  
 	    }
	    return true;  
	}   
	  
	function isNumber(str)          // 判断是否为非负整数  
	{  
	    var rx = /^[0-9]+$/;  
	    return rx.test(str);  
	} 
	
	<%
	String result = (String)request.getAttribute("result");
	String error = (String)request.getAttribute("error");
	if(result != null) {%>
		swal("<%=result %>", "成功", "success");
	<%
		request.removeAttribute("result");
	} 
	if(error != null) {%>
		swal("<%=error %>", "失败", "warning");
	<%
		request.removeAttribute("error");
	} %>
</script>
</body>
</html>